package cn.stronglink.assetmanage.business.check.model;

import java.util.List;

import cn.stronglink.assetmanage.MyApplication;
import cn.stronglink.assetmanage.dao.AssetDao;
import cn.stronglink.assetmanage.dao.CheckDao;
import cn.stronglink.assetmanage.dao.DaoManager;
import cn.stronglink.assetmanage.entity.Asset;
import cn.stronglink.assetmanage.entity.Brand;
import cn.stronglink.assetmanage.entity.Check;
import cn.stronglink.assetmanage.entity.Room;
import cn.stronglink.assetmanage.entity.Type;
import cn.stronglink.assetmanage.utils.Constants;

/**
 * 已经入库数据操作
 * Created by chencongcong on 2018/6/14.
 */

public class CheckedAssetModel {
    /**
     * 根据表单号获得该表单中已入库的资产数据，4为入库
     *
     * @param orderNo
     * @return
     */
    public List<Asset> getDataByOrderNo(String orderNo) {
        List<Asset> assetList = DaoManager.
                getDaoSession(MyApplication.APP_CONTEXT).getAssetDao().
                queryBuilder().where(AssetDao.Properties.OrderNo.eq(orderNo)).list();
        DaoManager.getDaoSession(MyApplication.APP_CONTEXT).clear();
        if (assetList != null) {
            return assetList;
        }
        return null;
    }

    public Check getCheckByOrderNo(String orderNo) {
        List<Check> checkList = DaoManager.
                getDaoSession(MyApplication.APP_CONTEXT).getCheckDao().queryBuilder().distinct()
                .orderDesc(CheckDao.Properties.Id_).
                        where(CheckDao.Properties.Id_.eq(orderNo)).list();
        if (checkList != null && checkList.size() > 0) {
            DaoManager.getDaoSession(MyApplication.APP_CONTEXT).clear();
            Check check = checkList.get(0);
            if (check != null) {
                return check;
            }
        }
        return null;
    }

}
